package com.zrrd.javaSEPlus._05_annotation;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author WanJl
 * @version 1.0
 * @title UseTest
 * @description
 * @create 2023/11/18 19:18
 */
public class AnnotationDemo03 {
    public static void main(String[] args) throws Exception {
        //1.获取Demo02的字节码文件对象
        //1.获取Class对象
        Class clazz = Class.forName("com.zrrd.javaSEPlus._05_annotation.Demo02");
        //反射获取一个对象
        Demo02 demo02 =(Demo02) clazz.newInstance();
        //2.获取里面的所有方法
        Method[] methods = clazz.getDeclaredMethods();
        //3.for循环
        for (Method method : methods) {
            //判断当前的方法上面是否有注解
            if (method.isAnnotationPresent(Test.class)){
                method.invoke(demo02);
            }
        }
    }
}
